# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         计算质数2
# Description:
# Author:       $赵怡蕾
# Date:         2019/3/6
#-------------------------------------------------------------------------------

# 计算 2000以内的质数,以字典的形式保存
#     eg: {
#         '1到99':[2,3...],
#         '100到999':[101,...],
#         '1000到1999':[...]
#         }


zhshu_dict1 = {
    '1到99': [],
    '100到999': [],
    '1000到1999': [],
}
# 获取质数
list1 = []
def get_zhsh(start,end):
    leap = 1
    for i in range(start, end):
        k = int(i / 2) + 1
        for j in range(2, k):
            if (i % j == 0):
                leap = 0
                break
        if leap:
            list1.append(i)
        leap = 1
    return list1

# 按区间计算质数
def zhsh(*zhshu_dict):
    for i in list1:
        if i<=100:
            zhshu_dict1['1到99'].append(i)
        elif i>100 and i<=1000:
            zhshu_dict1['100到999'].append(i)
        else:
            zhshu_dict1['1000到1999'].append(i)

# 测试代码
if __name__ == '__main__':
    zhsh(*get_zhsh(1,2000))
print(zhshu_dict1)
